<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading" v-if="false">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="group" class="menu" node-key="id" :data="group" :current-node-key="''"
						:highlight-current="true" :expand-on-click-node="false" :default-expand-all="true"
						:filter-node-method="groupFilterNode" @node-click="groupClick">

						<template #default="{node, data}">
							<span class="custom-tree-node">
								<span class="label">{{ data.cat_name }}</span>
								<span class="code" v-if="false">{{ node.name }}</span>
								<span class="do">
									<el-button-group>


									</el-button-group>
								</span>
							</span>
						</template>

					</el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<div>
				<el-card shadow="never">
					<sc-select-filter :data="state" :selected-values="selectedValues" :label-width="120"
						@on-change="stateChange"></sc-select-filter>
				</el-card>
			</div>
			<el-header>
				<div class="left-panel">
					<el-date-picker v-if="false" v-model="search.dateRange" type="daterange" align="right" unlink-panels
						range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :shortcuts="shortcuts"
						value-format="YYYY-MM-DD">
					</el-date-picker>
					<div class="right-panel-search" style="padding-left: 0px;">
						<el-input @keyup.enter="upsearch" v-model="search.keyword" placeholder="客户姓名" clearable>
						</el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch">查询</el-button>
					</div>
				</div>
				<div class="right-panel" v-if="false">
					<div class="right-panel-search">
						<sc-file-export :apiObj="$API.system.order.fileExport" :data="{dateRange:search.dateRange}"
							fileName="订单明细"></sc-file-export>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :pageSize="20" :apiObj="apiObj" @selection-change="selectionChange" stripe
					remoteSort remoteFilter>
					<el-table-column label="编号" prop="编号" width="150"></el-table-column>
					<el-table-column label="姓名/性别" prop="姓名" width="150">
						<template #default="scope">
							<el-button link size="default" class="selectable-btn"
								@dblclick.native="table_show(scope.row, scope.$index)">

								<el-icon v-if="scope.row.性别=='男'" class="el-icon--right" color="#409EFF">
									<Male />
								</el-icon>
								<el-icon v-if="scope.row.性别=='女'" class="el-icon--right" color="#F56C6C">
									<Female />
								</el-icon>
								&nbsp;
								{{scope.row.姓名}}


							</el-button>
						</template>
					</el-table-column>

					<el-table-column label="年龄" prop="年龄" width="80"></el-table-column>
					<el-table-column label="出生日期" prop="出生日期" width="150"></el-table-column>
					<el-table-column label="最后拍片时间" prop="最后拍片时间" width="170"></el-table-column>

					<el-table-column label="所属门店" width="80">
						东盟
					</el-table-column>

					<el-table-column label="操作" fixed="right" align="right" width="160">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small"
									@click="table_show(scope.row, scope.$index)">看片</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>



	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
	import saveDialog from './save'

	import scSelectFilter from '@/components/scSelectFilter'

	export default {
		name: 'cbct',
		components: {
			saveDialog,
			scSelectFilter,
		},
		data() {
			return {
				state: [{
					title: "患者性别",
					key: "性别",
					multiple: false,
					options: [{
							label: "全部",
							value: ""
						},
						{
							label: "男",
							value: "男"
						},
						{
							label: "女",
							value: "女"
						}
					]
				}, {
					title: "CT类型",
					key: "type",
					options: [{
							label: "全部",
							value: null
						},
						{
							label: "CBCT",
							value: "CBCT",
							icon: "el-icon-flag"
						},
						{
							label: "全景片",
							value: "全景片",
							icon: "el-icon-bottom-left"
						},
						{
							label: "头侧",
							value: "头侧",
							icon: "el-icon-bottom-left"
						},
						{
							label: "其他",
							value: "其他",
							icon: "el-icon-bottom-left"
						}
					]
				}, {
					title: "最后拍片时间",
					key: "最后拍片时间",
					options: [{
							label: "全部",
							value: null
						},
						{
							label: "1周",
							value: "7",
							icon: "el-icon-flag"
						},
						{
							label: "1个月",
							value: "31",
							icon: "el-icon-bottom-left"
						},
						{
							label: "3个月",
							value: "90",
							icon: "el-icon-bottom-left"
						},
						{
							label: "半年",
							value: "180",
							icon: "el-icon-bottom-left"
						},
						{
							label: "1年",
							value: "360",
							icon: "el-icon-bottom-left"
						},
						{
							label: "1年前",
							value: "360+",
							icon: "el-icon-bottom-left"
						}
					]
				}],
				selectedValues: {
					state: [""],
					type: [""]
				},
				filterData: {},

				dialog: {
					save: false
				},


				showGrouploading: false,
				groupFilterText: '',
				group: [],
				apiObj: this.$API.bole.ct.patient,
				selection: [],
				search: {
					keyword: null
				}
			}
		},
		watch: {
			groupFilterText(val) {
				this.$refs.group.filter(val);
			}
		},
		mounted() {
			this.getGroup()
		},
		methods: {



			stateChange(e) {
				var params = {
					state: e
				}
				this.$refs.table.upData(params)
			},
			//添加
			add() {
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open()
				})
			},
			//查看
			table_show(row) {
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('show').setData(row)
				})
			},
			//删除
			async table_del(row, index) {
				var reqData = {
					id: row.id
				}
				var res = await this.$API.system.goods.remove.post(reqData);
				if (res.code == 0) {
					this.$refs.table.tableData.splice(index, 1);
					this.$message.success(res.msg)
				} else {
					this.$alert(res.message, "提示", {
						type: 'error'
					})
				}
			},
			//批量删除
			async batch_del() {


			},
			//表格选择后回调事件
			selectionChange(selection) {
				this.selection = selection;
			},
			//加载树数据
			async getGroup() {
				/*
				this.showGrouploading = true;
				var res = await this.$API.system.category.tree.get();
				this.showGrouploading = false;
				var allNode = {
					id: '',
					cat_name: '所有',
					dept_path: ''
				}
				res.data.unshift(allNode);
				this.group = res.data;
				*/
			},
			//树过滤
			groupFilterNode(value, data) {
				if (!value) return true;
				return data.cat_name.indexOf(value) !== -1;
			},
			//树点击事件
			groupClick(data) {
				var params = {
					category_id: data.id
				}
				this.$refs.table.upData(params)
			},
			//搜索
			upsearch() {
				this.$refs.table.upData(this.search)
			},
			//本地更新数据
			handleSuccess(data, mode) {
				if (mode == 'add') {
					this.$refs.table.refresh()
				} else if (mode == 'edit') {
					this.$refs.table.refresh()
				}
			}
		}
	}
</script>

<style scoped>
	.selectable-btn {
		user-select: text;
		-webkit-user-select: text;
		-moz-user-select: text;
		-ms-user-select: text;

		/* 如果需要更自然的文字选择体验可以加这个 */
		cursor: text !important;
	}



	.gender-container {
		display: flex;
		gap: 20px;
	}

	.gender-item {
		display: flex;
		align-items: center;
		gap: 8px;
		padding: 12px;
		border-radius: 4px;
	}

	.male {
		color: #409EFF;
		background-color: rgba(64, 158, 255, 0.1);
	}

	.female {
		color: #F56C6C;
		background-color: rgba(245, 108, 108, 0.1);
	}
</style>
